<template>
    <view>
        <view class="items">
            <view>配置属性</view>
            <view @click="show = true">{{ typeName }}</view>
        </view>
        <view class="item">
            <view>排序</view>
            <view><input type="number" placeholder="数字最大排在前面(默认为0)" v-model="weigh"></view>
        </view>
        <view class="item">
            <view>配置名称</view>
            <view><input type="text" placeholder="请输入配置名称" v-model="default_value"></view>
        </view>
        <view class="submit" @click="submit">确认</view>
        <u-picker :show="show" :columns="columns" keyName="name" @confirm="confirmType" @cancel="closeType"></u-picker>
    </view>
</template>

<script>
import { defaultsetadd } from "@/api/user.js"
export default {
    components: {},
    props: {},
    data() {
        return {
            type: '',
            typeName: '请选择配置属性',
            weigh: '',
            show: false,
            id: '',
            default_value: '',
            columns: [
                [{
                    name: '运输物料',
                    id: 1
                }, {
                    name: '运输线路',
                    id: 2,
                }, {
                    name: '吨位立方',
                    id: 3,
                }, {
                    name: '运输里程',
                    id: 4,
                }]
            ],
            owen_user_id: ''
        };
    },
    watch: {},
    methods: {
        confirmType(e) {
            console.log(e)
            this.typeName = e.value[0].name
            this.type = e.value[0].id
            this.show = false;
        },
        closeType() {
            this.typeName = '请选择配置属性'
            this.type = ''
            this.show = false;
        },
        submit() {
            if (this.type == '') {
                uni.showToast({
                    title: '请选择配置属性',
                    icon: 'none',
                    mask: true
                })
                return false;
            }
            if (this.default_value == '') {
                uni.showToast({
                    title: '请输入配置名称',
                    icon: 'none',
                    mask: true
                })
                return false;
            }
            console.log(this.owen_user_id)
            defaultsetadd({
                set_type: this.type,
                weigh: this.weigh || 0,
                default_value: this.default_value,
                owen_user_id: this.owen_user_id,
                id: this.id
            }).then(res => {
                console.log(res)
                if (res.code == 1) {
                    uni.showToast({
                        title: '成功～',
                        icon: 'none',
                        mask: true
                    })
                    setTimeout(() => {
                        uni.navigateBack({ delta: 1 })
                    }, 2000)
                }
            })
        }
    },
    onShow() { },
    onLoad(option) {
        if (option.type == 'edit') {
            uni.setNavigationBarTitle({
                title: '编辑配置'
            });
            const item = JSON.parse(decodeURIComponent(option.info));
            console.log(item)
            this.owen_user_id = item.owen_user_id;
            this.type = item.set_type;
            this.default_value = item.default_value;
            this.id = item.id;
            this.weigh = item.weigh
            console.log(this.owen_user_id)
            this.typeName = item.set_type == 1 ? '运输物料' : item.set_type == 2 ? '运输路线' : item.set_type == 3 ? '吨位立方' : item.set_type == 4 ? '运输物料' : ''
        } else {
            this.owen_user_id = option.owen_user_id;
        }

        console.log(option)
    },
};
</script>
<style scoped lang='scss'>
.item {
    width: 94%;
    height: 90rpx;
    border-bottom: 1px solid #efefef;
    margin: auto;
    display: flex;
    line-height: 90rpx;

    view:nth-child(1) {
        width: 30%;
        font-size: 28rpx;
        font-weight: 600;
    }

    view:nth-child(2) {
        width: 70%;

        input {
            font-size: 28rpx;
            width: 100%;
            height: 100%;
            text-align: right;
        }

    }
}

.items {
    width: 94%;
    height: 90rpx;
    border-bottom: 1px solid #efefef;
    margin: auto;
    display: flex;
    line-height: 90rpx;

    view:nth-child(1) {
        width: 30%;
        font-size: 28rpx;
        font-weight: 600;
    }

    view:nth-child(2) {
        width: 70%;
        text-align: right;
        font-size: 28rpx;
        color: $uni-color-primary;
    }
}

.submit {
    width: 94%;
    height: 90rpx;
    background-color: $uni-color-primary;
    border-radius: 50rpx;
    margin: auto;
    margin-top: 130rpx;
    text-align: center;
    line-height: 90rpx;
    color: #fff;
}
</style>